package com.example.ndkjnidemo.home.arraycopy;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.LogUtils;
import com.example.ndkjnidemo.R;

public class ArrayCopyActivity extends AppCompatActivity {

    static {
        System.loadLibrary("ndk-jni");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_array_copy);

        //
        Student[] srcStus = new Student[10];
        //对源数组的赋值
        for (int i = 0; i < srcStus.length; i++) {
            String name = "姓名:" + i;
            srcStus[i] = new Student(name, i);
        }
        //创建目标数组
        Student[] dstStus = new Student[srcStus.length];

        //进行数组的拷贝
        arrayCopy(srcStus, 0, dstStus, 0, srcStus.length);

        //打印拷贝后的数组
        for (Student stu : dstStus) {
            LogUtils.i("拷贝后结果:", stu.toString());
        }
    }

    /**
     * 数组拷贝
     *
     * @param arraySrc   源数组
     * @param srcPos     源数组开始拷贝的位置
     * @param arraDst    目标数组
     * @param dstPos     目标数组开始赋值的位置
     * @param copyLength 拷贝的长度
     */
    public native void arrayCopy(Object arraySrc, int srcPos, Object arraDst, int dstPos, int copyLength);
}
